package cn.wegoteam.shop.adm.action;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.ParentPackage;
import org.apache.struts2.convention.annotation.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import cn.wegoteam.shop.action.BaseAction;
import cn.wegoteam.shop.inter.CartServiceInter;
import cn.wegoteam.shop.po.Cart;

@ParentPackage("manage")
@Namespace("/")
@Controller
public class ManCartAction extends BaseAction<Cart>{
	/**
	 * 
	 */
	private static final long serialVersionUID = -7214652284224332303L;
	@Autowired
	private CartServiceInter cartService;

	@Action(value = "manageCartList", results = { @Result(name = SUCCESS, location = MANAGE
			+ "list.jsp") })
	public String manageCartList() {
		request.setAttribute("order.id", getParameter("order.id", ""));
		return SUCCESS;
	}

	@Action(value = "manageLoadCartList")
	public void loadCartList() {
		int pageSize = getIntParameter("pagesize");
		int currentPage = getIntParameter("page");
		map.put("order.id", model.getOrder().getId());
		pageBean.setSize(pageSize == 0 ? defaultSize : pageSize);
		pageBean.setCurrentPage(currentPage == 0 ? 1 : currentPage);
		pageBean.setTotalPage(getIntParameter("totalPage"));
		writeStringToResponse(cartService.getJsonList(pageBean,map,null,request));
	}

	@Action(value = "manageFindCartById", results = { @Result(name = SUCCESS, location = MANAGE
			+ "addCart.jsp") })
	public String findCartById() {
		if (model.getId() != null)
			model = cartService.get(model.getId());
		return SUCCESS;
	}

	@Action(value = "manageAddCart")
	public String addCart() {
			cartService.saveOrUpdate(model);
			return OPTRESULTSUCCESS;
	}

	@Action(value = "manageDeleteCart")
	public void deleteCart() {
		writeStringToResponse(cartService.delete(model));
	}

	/****************************************************** get() and set() ***********************************/


}
